﻿using A.M.ETO;
using AutoMapper;
using J.M.Inventory.Application.IInventoryServices;
using J.M.Inventory.Domain.DTO;
using J.M.Inventory.Domain.Entity;
using J.M.Inventory.Infrastruecure.IInventoryRepository;
using J.M.Inventory.Infrastruecure.InventoryRepository;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Expressions;

namespace J.M.Inventory.Read.API.Controllers
{
    /// <summary>
    /// 仓库表
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseReadController : ControllerBase
    {
        private readonly  IWarehouseServices warehouseServices;

        public WarehouseReadController(IWarehouseServices warehouseServices)
        {
            this.warehouseServices = warehouseServices;
        }
        /// <summary>
        /// 仓库树的显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<TreeDTO> GetWarehouse(string? code)
        {
            return warehouseServices.GetWarehouse("M", code);
        }
        /// <summary>
        /// 修改子集
        /// </summary>
        /// <param name="warehouseDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public int TreeUpd(WarehouseDTO warehouseDTO)
        {
            return warehouseServices.TreeUpd(warehouseDTO);
        }
        /// <summary>
        /// 删除子集
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public int DeleteTree(string id)
        {
            return warehouseServices.DeleteTree(id);
        }
        /// <summary>
        /// 添加时候用的树形
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<TreeDTO> AddFromTree()
        {
            return warehouseServices.AddFromTree();
        }
        /// <summary>
        /// 添加仓库
        /// </summary>
        /// <param name="warehouseDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiReturn<string> AddFromWarehouse(WarehouseDTO warehouseDTO)
        {
            return warehouseServices.AddFromWarehouse(warehouseDTO);
        }
        /// <summary>
        /// 反填仓库信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<warehouse> FindWarehouse(string? code)
        {
            return  await warehouseServices.FindWarehouse(code);

        }
    }
}
